﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using LotteryWCF.AdminConstract;
using LotteryWCF.Commom;
using System.Data;
using System.Threading;
using System.ServiceModel.Activation;
using System.Web;
namespace LotteryWCF
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“LotteryAdmin”。
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class LotteryAdmin : ILotteryAdmin
    {
        #region xjw
        public bool AddMember(User info)
        {
            string sql = "select * from UserInfo where UserID='" + info.UserId + "'";
            if (SqlHelper.getInstance.ExcuteExist(sql))
                return false;
            string[] sqls = new string[2];
            User admin = GetAdmin();
            string sql_1 = String.Format(@"insert into UserInfo(UserID,UserPwd,ParentUID,RegTime,IsOnline,IsActive,Bonus,FullPath,RoleID)
                              values('{0}','{1}',{2},'{3}',{4},{5},{6},'{7}',{8})",
                            info.UserId, info.UserPwd, admin.ID, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), 0,
                            1, info.Bonus, admin.FullPath + admin.ID.ToString() + "/", info.RoleID);
            sqls[0] = sql_1;
            string sql_2 = "insert into CapitalInfo(userID,GameScores,EnableScores,DisableScores) values('" + info.UserId + "',0,0,0)";
            sqls[1] = sql_2;
            bool returnValue = SqlHelper.getInstance.ExcuteTrancationForSQL(sqls);
            User user = SqlHelper.getInstance.ExcuteForList<User>(sql).FirstOrDefault();
            if (user != null)
            {
                sql = "update CapitalInfo set ID=" + user.ID + " where UserID='" + info.UserId + "'";
                SqlHelper.getInstance.ExcuteNonQuery(sql);
            }
            WriteLog("新增会员", "新增会员:[" + info.UserId + "]" + (returnValue == true ? "成功" : "失败") + ",Value=" + GetLogContent<User>(info));
            return returnValue;
        }
        public bool DeleteMember(MemberList info)
        {
            string sql = "select * from UserInfo where ID=" + info.ParentUID;
            MemberList parentUser = SqlHelper.getInstance.ExcuteForList<MemberList>(sql).FirstOrDefault();
            if (parentUser == null)
                return false;
            string[] sqls = new string[11];
            sqls[0] = string.Format("update UserInfo set fullpath=replace(fullpath,'/{0}/','/'),ParentUID={1} where fullpath like '%/{0}/%'",
                 info.ID, info.ParentUID);
            sqls[1] = "delete from UserInfo where UserID='" + info.UserID + "'";
            sqls[2] = "delete from  CapitalInfo where UserID='" + info.UserID + "'";
            sqls[3] = "delete from BankInfo where UserID='" + info.UserID + "'";
            sqls[4] = "delete from ProfitLoss where RecordID in(select RecordID from BetRecord where UserID='" + info.UserID + "')";
            sqls[5] = "delete from ProfitLoss where RecordID in(select RecordID from MoneyOutInfo where UserID='" + info.UserID + "')";
            sqls[6] = "delete from ProfitLoss where RecordID in(select RecordID from MoneyInInfo where UserID='" + info.UserID + "')";
            sqls[7] = "delete from BetRecord where  UserID='" + info.UserID + "'";
            sqls[8] = "delete from  MoneyOutInfo where UserID='" + info.UserID + "'";
            sqls[9] = "delete from MoneyInInfo where UserID='" + info.UserID + "'";
            sqls[10] = "delete from BonusInfo where UserID='" + info.UserID + "'";
            bool execResult = SqlHelper.getInstance.ExcuteTrancationForSQL(sqls);
            WriteLog("删除会员", "删除会员:[" + info.UserID + "]" + (execResult == true ? "成功" : "失败"));
            return execResult;
        }
        public bool FrozenUser(int isActive, string userId)
        {
            string sql = "update UserInfo set IsActive=" + isActive + " where UserID='" + userId + "'";
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("锁定会员", "锁定会员:[" + userId + "]" + (execResult == true ? "成功" : "失败"));
            return execResult;
        }
        public List<MemberList> GetLowerMemberByUID(Int64 ID)
        {
            string sql = @"select t1.ID,t1.UserID,t2.RoleName,t1.RegTime,t4.UserID as ParentUserID,
                            t1.LastLoginTime,t1.IsOnline,t1.IsActive,t1.Bonus,t1.UserPwd,t1.RoleID,t1.ParentUID,t1.FullPath 
                          from UserInfo t1 left join RoleInfo t2 on t1.RoleID=t2.RoleID 
                           left join UserInfo t4 on t4.ID=t1.ParentUID 
                            where t1.ID=" + ID + " or t1.FullPath like'%/" + ID + "/%'";
            return SqlHelper.getInstance.ExcuteForList<MemberList>(sql);
        }
        public Dictionary<string, string> GetOverAllCfg()
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            string sql = "select * from OverallConfig";
            DataTable dtResult = SqlHelper.getInstance.ExcuteForDataTable(sql);
            foreach (DataRow dr in dtResult.Rows)
            {
                dic.Add(dr["key"].ToString(), dr["value"].ToString());
            }
            return dic;
        }
        public List<MemberList> GetMemberListData(string UserID, int IsOnline, int IsActive, int RoleID, string UID)
        {
            string where = "where t1.ParentUID is not null";
            if (!string.IsNullOrEmpty(UserID))
            {
                where += " and t1.UserID like '%" + UserID + "%'";
            }
            if (IsOnline != 0)
            {
                where += IsOnline == 1 ? " and t1.IsOnline=1" : " and t1.IsOnline=0";
            }
            if (IsActive != 0)
            {
                where += IsActive == 1 ? " and t1.IsActive=0" : " and t1.IsActive=1";
            }
            if (RoleID != 0)
            {
                where += RoleID == 1 ? " and t1.RoleID=2" : " and t1.RoleID=3";
            }
            if (UID.ToString().Trim() != string.Empty)
            {
                where += (" and t1.ID=" + UID);
            }
            string sql = @"select t1.ID,t1.UserID,t2.RoleName,t1.RegTime,t3.GameScores,t4.UserID as ParentUserID,
                            t1.LastLoginTime,t1.IsOnline,t1.IsActive,t1.Bonus,t1.UserPwd,t1.RoleID,t1.ParentUID,t1.FullPath    
                          from UserInfo t1 left join RoleInfo t2 on t1.RoleID=t2.RoleID left join 
                          CapitalInfo t3 on t1.UserID=t3.UserID left join UserInfo t4 on t4.ID=t1.ParentUID
                          " + where;
            List<MemberList> list = SqlHelper.getInstance.ExcuteForList<MemberList>(sql);
            return list;
        }
        public int GetMemberListDataCount(string UserID, int IsOnline, int IsActive, int RoleID, int PageSize)
        {
            string where = "where ParentUID is not null";
            if (!string.IsNullOrEmpty(UserID))
            {
                where += " and UserID like '%" + UserID + "%'";
            }
            if (IsOnline != 0)
            {
                where += IsOnline == 1 ? " and IsOnline=1" : " and IsOnline=0";
            }
            if (IsActive != 0)
            {
                where += IsActive == 1 ? " and IsActive=0" : " and IsActive=1";
            }
            if (RoleID != 0)
            {
                where += RoleID == 1 ? " and RoleID=2" : " and RoleID=3";
            }
            string sql = @"select Count(*) from UserInfo " + where;
            return int.Parse(Math.Ceiling(Convert.ToDouble(SqlHelper.getInstance.ExcuteScalar(sql).ToString()) / Convert.ToDouble(20)).ToString());
        }
        public MemberInfo GetMemberInfoByUID(string UserID)
        {
            string sql = @"select UserPwd,IsActive,Bonus,RoleID,ParentUID,FullPath  from UserInfo where UserID='" + UserID + "'";
            return SqlHelper.getInstance.ExcuteForList<MemberInfo>(sql).FirstOrDefault();
        }
        public List<MemberBankInfo> GetMemberBankInfoByUID(string UserID)
        {
            string sql = @"select BankType,BankPwd,UserName,CardNo from BankInfo where UserID='" + UserID + "'";
            return SqlHelper.getInstance.ExcuteForList<MemberBankInfo>(sql);
        }
        public Capital GetCapitalByUID(string UserID)
        {
            string sql = @"select GameScores,EnableScores,DisableScores from CapitalInfo where UserID='" + UserID + "'";
            return SqlHelper.getInstance.ExcuteForList<Capital>(sql).FirstOrDefault();
        }
        public bool UpdateMemberInfoByUID(MemberInfo mInfo, string UserID)
        {
            string sql = "Update UserInfo set UserPwd='" + mInfo.UserPwd + "',IsActive=" + mInfo.IsActive + ",Bonus=" + mInfo.Bonus
                          + ",RoleID=" + mInfo.RoleID + " where UserID='" + UserID + "'";
            bool execResult = SqlHelper.getInstance.ExcuteNonQuery(sql) > 0 ? true : false;
            WriteLog("修改会员基本信息", "修改会员:[" + UserID + "]基本信息" + (execResult == true ? "成功" : "失败") + ",Value=" + GetLogContent<MemberInfo>(mInfo));
            return execResult;
        }

        public bool UpdateMemberBankInfoByUID(MemberBankInfo MBInfo, string UserID)
        {
            string sql = string.Empty;
            sql = string.Format("select count(*) from BankInfo where UserID='{0}' and BankType='{1}'", UserID, MBInfo.BankType);
            if (Convert.ToInt32(SqlHelper.getInstance.ExcuteScalar(sql).ToString()) > 0)
            {
                sql = string.Format(@"Update BankInfo set BankPwd='{0}',CardNo='{1}',UserName='{2}',BankType='{3}' where UserID='{4}'",
    MBInfo.BankPwd, MBInfo.CardNo, MBInfo.UserName, MBInfo.BankType, UserID);
            }
            else
            {
                sql = string.Format(@"insert into BankInfo(UserID,BankPwd,CardNo,UserName,BankType)values('{0}','{1}','{2}','{3}','{4}')",
                    UserID, MBInfo.BankPwd, MBInfo.CardNo, MBInfo.UserName, MBInfo.BankType);
            }
            bool execResult = SqlHelper.getInstance.ExcuteNonQuery(sql) > 0 ? true : false;
            WriteLog("修改会员银行信息", "修改会员:[" + UserID + "]银行信息" + (execResult == true ? "成功" : "失败") + ",Value=" + GetLogContent
                <MemberBankInfo>(MBInfo));
            return execResult;
        }

        public bool UpdateCapitalByUID(Capital capitalInfo, string UserID)
        {
            string sql = @"Update CapitalInfo set GameScores=" + capitalInfo.GameScores + ",EnableScores=" + capitalInfo.EnableScores + ",DisableScores=" + capitalInfo.DisableScores + " where UserID='" + UserID + "'";
            bool execResult = SqlHelper.getInstance.ExcuteNonQuery(sql) > 0 ? true : false;
            WriteLog("修改会员资金信息", "修改会员:[" + UserID + "]资金信息" + (execResult == true ? "成功" : "失败") + ",Value=" + GetLogContent
               <Capital>(capitalInfo));
            return true;
        }
        public List<MemberList> GetMemberListByID(string ID, string UserID)
        {
            string sql = @"select t1.ID,t1.UserID,t2.RoleName,t1.RegTime,t1.LastLoginTime,t1.IsOnline,t1.IsActive, 
                                        case when t3.GameScores is null then 0 else GameScores end GameScores
                                        from UserInfo t1 left join RoleInfo t2 on t1.RoleID=t2.RoleID 
                                        left join CapitalInfo t3 on t3.UserID=t1.UserID 
                                        where t1.ParentUID is not null ";
            if (ID != string.Empty)
            {
                sql += (" and t1.ID =" + ID);
            }
            if (UserID != string.Empty)
            {
                sql += (" and t1.UserID='" + UserID + "'");
            }
            return SqlHelper.getInstance.ExcuteForList<MemberList>(sql);
        }

        public bool MoneyIn(string UID, double Money)
        {
            MoneyInList mi = new MoneyInList()
            {
                UserID = UID,
                Amount = Money,
                DealTime = DateTime.Now
            };
            int recordid = SqlHelper.getInstance.ExcuteInsertReturnAutoID<MoneyInList>(mi, "MoneyInInfo", "");
            string[] sqls = new string[3];
            sqls[0] = string.Format(@"Update CapitalInfo set EnableScores=EnableScores+{0},GameScores=GameScores+{0}
                                    where UserID='{1}'", Money, UID);
            sqls[1] = string.Format(@"Insert into ProfitLoss select t1.UserID,'{0}','{1}','{2}',t1.EnableScores,{4},{5}
                                      from CapitalInfo t1 where t1.[UserID]='{3}'"
                                      , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                      string.Format("充值{0}元,订单号:CZ{1}", Money, recordid), "充值", UID, recordid, Money);
            sqls[2] = string.Format(@"Insert into ProfitLoss select t1.UserID,'{0}','{1}','{2}',t1.GameScores,{4},{5}
                                      from CapitalInfo t1 where t1.[UserID]='{3}'"
                                      , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                      string.Format("充值{0}元,订单号:CZ{1}", Money, recordid), "充值", GetAdmin().UserId, recordid, Money);
            bool execResult = (SqlHelper.getInstance.ExcuteTrancationForSQL(sqls));
            if (execResult == false)
            {
                SqlHelper.getInstance.ExcuteNonQuery("delete from MoneyInInfo where RecordID=" + recordid.ToString());
            }
            WriteLog("充值处理", "处理会员:[" + UID + "]充值" + (execResult == true ? "成功" : "失败") + ",充值金额:" + Money.ToString());
            return execResult;
        }

        public List<MoneyInList> GetMoneyInListByUID(string UID)
        {
            string sql = string.Format(@"select UserID,Amount,DealTime from MoneyInInfo where UserID='{0}' order by DealTime desc", UID);
            return SqlHelper.getInstance.ExcuteForList<MoneyInList>(sql);
        }
        public List<MoneyOutList> GetMoneyOutList()
        {
            string sql = @"select UserID,Amount,ApplyTime,Status,DealTime,RecordID,BankType from MoneyOutInfo where Status=0";
            return SqlHelper.getInstance.ExcuteForList<MoneyOutList>(sql);
        }
        User GetUpperUser(string userid)
        {
            string sql = "select FullPath from UserInfo where UserID='" + userid + "'";
            string fullPath = SqlHelper.getInstance.ExcuteScalar(sql).ToString();
            string[] ids = fullPath.Split('/');
            if (ids.Length > 2)
            {
                sql = "select * from UserInfo where ID=" + ids[ids.Length - 2];
                return SqlHelper.getInstance.ExcuteForList<User>(sql).FirstOrDefault();
            }
            else
                return null;
        }
        public List<MoneyOutList> GetMoneyOutListBy(string UID, DateTime dtFrom, DateTime dtTo, int Status)
        {
            string sql = string.Format(@"select UserID,Amount,ApplyTime,Status,DealTime,RecordID,BankType from MoneyOutInfo where UserID like '%{0}%' 
                                       and ApplyTime>='{1}' and ApplyTime<='{2}' ", UID, dtFrom.ToString("yyyy-MM-dd HH:mm:ss"), dtTo.ToString("yyyy-MM-dd HH:mm:ss"));
            if (Status != -1)
                sql += (" and Status=" + Status);
            return SqlHelper.getInstance.ExcuteForList<MoneyOutList>(sql);
        }
        public bool DealMoneyOut(MoneyOutList info)
        {
            bool execResult;
            if (info.Status == 2)
            {
                string[] sqls0 = new string[3];
                sqls0[0] = string.Format("update MoneyOutInfo set Status=2,DealTime='{0}' where RecordID={1}",
                                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), info.RecordID);
                sqls0[1] = string.Format("Update CapitalInfo set DisableScores=DisableScores-{0},EnableScores=EnableScores+{0} where UserID='{1}'",
                                        info.Amount, info.UserID);
                sqls0[2] = string.Format(@"Insert into ProfitLoss select t1.UserID,'{0}','{1}','{2}',t1.EnableScores,{4},{5}
                                      from CapitalInfo t1  where t1.[UserID]='{3}'"
                                          , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), string.Format("提现{0}元被拒绝,订单号:TX{1}", info.Amount, info.RecordID),
                                          "提现", info.UserID, info.RecordID, info.Amount);
                execResult = SqlHelper.getInstance.ExcuteTrancationForSQL(sqls0);
                WriteLog("提现处理", "拒绝会员:[" + info.UserID + "]提现操作" + (execResult == true ? "成功" : "失败"));
                return execResult;
            }
            string[] sqls = null;
            string sql_0 = string.Format("update MoneyOutInfo set Status=1,DealTime='{0}' where RecordID={1}",
                                    DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), info.RecordID);
            string sql_1 = string.Format("Update CapitalInfo set DisableScores=DisableScores-{0},GameScores=GameScores-{0} where UserID='{1}'",
                                    info.Amount, info.UserID);
            string sql_2 = string.Format(@"Insert into ProfitLoss select t1.UserID,'{0}','{1}','{2}',t1.EnableScores,{4},{5}
                                      from CapitalInfo t1  where t1.[UserID]='{3}'"
                                      , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), string.Format("提现{0}元,订单号:TX{1}", info.Amount, info.RecordID),
                                      "提现", info.UserID, info.RecordID, info.Amount);
            string sql_3 = string.Format(@"Insert into ProfitLoss select t1.UserID,'{0}','{1}','{2}',t1.GameScores,{4},{5}
                                      from CapitalInfo t1  where t1.[UserID]='{3}'"
                                      , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), string.Format("提现{0}元,订单号:TX{1}", info.Amount, info.RecordID),
                                      "提现", GetAdmin().UserId, info.RecordID, 0 - info.Amount);
            string sql = string.Format("select count(*)  from MoneyOutInfo where UserID='{0}' and ApplyTime between '{1}' and '{2}'",
                                    info.UserID, DateTime.Now.ToString("yyyy-MM-dd 00:00:00"), DateTime.Now.ToString("yyyy-MM-dd 23:23:59"));
            if (Convert.ToInt32(SqlHelper.getInstance.ExcuteScalar(sql)) > 1)
            {
                sqls = new string[] { sql_0, sql_1, sql_2, sql_3 };
                execResult = SqlHelper.getInstance.ExcuteTrancationForSQL(sqls);
                WriteLog("提现处理", "处理会员:[" + info.UserID + "]提现" + (execResult == true ? "成功" : "失败") + ",提现金额:" + info.Amount.ToString());
                return execResult;
            }
            //提现返点
            User upperUser = GetUpperUser(info.UserID);//直接上级
            if (upperUser.UserId != GetAdmin().UserId)
            {
                string sql_4 = "update CapitalInfo set EnableScores=EnableScores+5,GameScores=GameScores+5 where UserID='" + upperUser.UserId + "'";
                string sql_5 = String.Format(@"insert into ProfitLoss select t1.UserID,'{1}','{2}','提现返点',t1.EnableScores,{3},5 
                                             from CapitalInfo t1  where t1.[UserID]='{0}'", upperUser.UserId,
                                   DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "下级会员[" + info.UserID + "]提现返点", info.RecordID);
                string sql_6 = "update CapitalInfo set EnableScores=EnableScores-5,GameScores=GameScores-5 where UserID='" + GetAdmin().UserId + "'";
                string sql_7 = String.Format(@"insert into ProfitLoss select t1.UserID,'{1}','{2}','提现返点',t1.GameScores,{3},5 
                                            from CapitalInfo t1  where t1.[UserID]='{0}'", GetAdmin().UserId,
                                   DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "会员[" + info.UserID + "]提现返点给其上级:" + upperUser.UserId, info.RecordID);
                User upperUpUser;//上上级
                if (upperUser != null)
                {
                    upperUpUser = GetUpperUser(upperUser.UserId);
                    if (upperUpUser.UserId != GetAdmin().UserId)
                    {
                        string sql_8 = "update CapitalInfo set EnableScores=EnableScores+3,GameScores=GameScores+3 where UserID='" + upperUpUser.UserId + "'";
                        string sql_9 = String.Format(@"insert into ProfitLoss select t1.UserID,'{1}','{2}','提现返点',t1.EnableScores,{3},3 
                                              from CapitalInfo t1  where t1.[UserID]='{0}'", upperUpUser.UserId,
                                           DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "下级会员[" + upperUser.UserId + "]的下级会员[" + info.UserID + "]提现返点", info.RecordID);
                        string sql_10 = "update CapitalInfo set EnableScores=EnableScores-3,GameScores=GameScores-3 where UserID='" + GetAdmin().UserId + "'";
                        string sql_11 = String.Format(@"insert into ProfitLoss select t1.UserID,'{1}','{2}','提现返点',t1.GameScores,{3},3 
                                             from CapitalInfo t1  where t1.[UserID]='{0}'", GetAdmin().UserId,
                                           DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "会员[" + info.UserID + "]提现返点给其上上级:" + upperUpUser.UserId, info.RecordID);

                        sqls = new string[] { sql_0, sql_1, sql_2, sql_3, sql_4, sql_5, sql_6, sql_7, sql_8, sql_9, sql_10, sql_11 };
                    }
                    else
                        sqls = new string[] { sql_0, sql_1, sql_2, sql_3, sql_4, sql_5, sql_6, sql_7 };
                }
                else
                {
                    sqls = new string[] { sql_0, sql_1, sql_2, sql_3, sql_4, sql_5, sql_6, sql_7 };
                }
            }
            else
            {
                sqls = new string[] { sql_0, sql_1, sql_2, sql_3 };
            }
            execResult = SqlHelper.getInstance.ExcuteTrancationForSQL(sqls);
            WriteLog("提现处理", "处理会员:[" + info.UserID + "]提现" + (execResult == true ? "成功" : "失败") + ",提现金额:" + info.Amount.ToString());
            return execResult;
        }
        public OverallConfig GetGlobalConfig()
        {
            string sql = "select [key],value from OverallConfig";
            DataTable dt = SqlHelper.getInstance.ExcuteForDataTable(sql);
            OverallConfig oconf = new OverallConfig();
            oconf.MaxBetCount = double.Parse(dt.Rows[0]["value"].ToString());
            oconf.MaxBetMoney = double.Parse(dt.Rows[1]["value"].ToString());
            oconf.MinOneBetMoney = double.Parse(dt.Rows[2]["value"].ToString());
            oconf.MaxOneBetMoney = double.Parse(dt.Rows[3]["value"].ToString());
            oconf.MaxOutMoneyOneDay = double.Parse(dt.Rows[4]["value"].ToString());
            oconf.MaxOutMoneyOneTime = double.Parse(dt.Rows[5]["value"].ToString());
            oconf.MinOutMoneyOneTime = double.Parse(dt.Rows[6]["value"].ToString());
            oconf.MaxOutMoneyTimesOneD = double.Parse(dt.Rows[7]["value"].ToString());
            oconf.MaxBonusPct = double.Parse(dt.Rows[8]["value"].ToString());
            oconf.KFSystem = dt.Rows[9]["value"].ToString();
            oconf.MemBonusIncrement = double.Parse(dt.Rows[10]["value"].ToString());
            return oconf;
        }
        public bool SaveGloablConfig(Dictionary<int, string> values)
        {
            string[] sqls = new string[values.Count];
            for (int i = 0; i < values.Count; i++)
            {
                sqls[i] = string.Format("update OverallConfig set Value='{0}' where id={1}", values[i], i + 1);
            }
            bool execResult = SqlHelper.getInstance.ExcuteTrancationForSQL(sqls);
            WriteLog("修改全局配置", "修改全局配置" + (execResult == true ? "成功" : "失败") + ",Value=" + GetLogContent(values));
            return true;
        }

        public List<LotteryNumsInfo> GetLotteryNumsInfoList(string IssueNums, DateTime dtFrom, DateTime dtTo, int LotteryType)
        {
            string sql = string.Empty;
            if (!string.IsNullOrEmpty(IssueNums))
            {
                sql = string.Format(@"select * from LotteryNumsInfo where IssueNo='{0}'", IssueNums);
            }
            else
            {
                sql = string.Format(@"select * from LotteryNumsInfo where LotteryTypeID={0} and AddTime>='{1}' and AddTime<='{2}' order by IssueNo desc", LotteryType, dtFrom.ToString("yyyy-MM-dd 00:00:00"), dtTo.ToString("yyyy-MM-dd 23:59:59"));
            }
            return SqlHelper.getInstance.ExcuteForList<LotteryNumsInfo>(sql);
        }
        public int UpdateLotteryNums(LotteryNumsInfo info)
        {
            int returnNum = 0;
            LotteryNumsInfo lottery = SqlHelper.getInstance.ExcuteForList<LotteryNumsInfo>(string.Format("select * from LotteryNumsInfo where IssueNo='{0}' and LotteryTypeID={1}", info.IssueNo, info.LotteryTypeID)).FirstOrDefault();
            if (lottery.LotteryNums == null || lottery.LotteryNums.Trim() == "")
            {

                string sql = string.Format("update LotteryNumsInfo set LotteryNums='{0}',UpdateTime='{1}',UpdateUser='{2}' where IssueNo='{3}' and LotteryTypeID={4}",
                                            info.LotteryNums, info.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss"),
                                            info.UpdateUser, info.IssueNo, info.LotteryTypeID);
                returnNum = SqlHelper.getInstance.ExcuteNonQuery(sql);
            }
            LotteryNumsInfo l = CreateModel(info);
            LotteryNumsInfo current = GetCurrenIssuNum((int)l.LotteryTypeID);
            if (current == null || Convert.ToInt64(current.IssueNo) < Convert.ToInt64(l.IssueNo))
            {
                int result = InsertLotteryNums(l);
                if (result > 0)
                    ThreadPool.QueueUserWorkItem(new WaitCallback((p) => GoPaiJiang((LotteryType)info.LotteryTypeID)));
            }
            WriteLog("手动开奖", "手动开奖:" + info.IssueNo + "期" + (returnNum > 0 ? "成功" : "失败") + ",Value" + GetLogContent<LotteryNumsInfo>(info));
            return returnNum;
        }
        public string GetCurrenIssuNo(string lotteryId)
        {
            if (lotteryId != "")
            {
                string sql = @"select LotteryTypeID from LotteryTypeInfo where LotteryName=(
                               select LotteryName from LotteryTypeInfo where LotteryTypeID=" + lotteryId +
                                    ") order by LotteryTypeID";
                lotteryId = SqlHelper.getInstance.ExcuteScalar(sql).ToString();
                sql = @"select issueno from LotteryNumsInfo 
                        where (LotteryNums='' or LotteryNums is null)
                        and LotteryTypeID=" + lotteryId + " order by LotteryDate desc";
                return "'" + SqlHelper.getInstance.ExcuteScalar(sql).ToString() + "'";
            }
            else
            {
                string _sql = "select Max(issueno),lotterytypeid from lotterynumsinfo group by lotterytypeid";
                DataTable rel = SqlHelper.getInstance.ExcuteForDataTable(_sql);
                string IssueNo = string.Empty;
                foreach (DataRow dr in rel.Rows)
                {
                    IssueNo += ("'" + dr[0].ToString() + "',");
                }
                return IssueNo.Length > 0 ? IssueNo.Substring(0, IssueNo.Length - 1) : IssueNo;
            }
        }
        public LotteryNumsInfo GetCurrenIssuNum(int lotteryId)
        {
            string sql = @"select * from LotteryNumsInfo 
            where (LotteryNums='' or LotteryNums is null)
            and LotteryTypeID=" + lotteryId + " order by LotteryDate desc";
            return SqlHelper.getInstance.ExcuteForList<LotteryNumsInfo>(sql).FirstOrDefault();
        }
        public LotteryNumsInfo GetLastLotteryNum(int lotteryId)
        {
            string sql = @"select * from LotteryNumsInfo 
            where  IssueNo=(select max(IssueNo) from LotteryNumsInfo
            where  LotteryNums!='' and LotteryNums is not null  and LotteryTypeID=" + lotteryId + @") order by LotteryDate desc";
            return SqlHelper.getInstance.ExcuteForList<LotteryNumsInfo>(sql).FirstOrDefault();
        }

        public int InsertLotteryNums(LotteryNumsInfo info)
        {
            LotteryNumsInfo lottery = GetCurrenIssuNum(Convert.ToInt32(info.LotteryTypeID));
            if (lottery != null && lottery.IssueNo == info.IssueNo && (lottery.LotteryNums == null || lottery.LotteryNums.Trim() == ""))
            {
                return 0;
            }
            else
            {
                string sql = string.Format(@"insert into oddsInfo(PlayTypeID,PlayTypeRadioID,Num,NumOdds,RemainderCount,IssueNo)
                            select PlayTypeID,PlayTypeRadioID,Num,NumOdds,
                            Allcount, '{0}' as IssueNo from defaultoddsinfo 
                            where playTypeID in(select distinct PlayTypeID from PlayTypeInfo where LotteryTypeID in 
                            (select LotteryTypeID from LotteryTypeInfo where LotteryID={1}))",
                           info.IssueNo, info.LotteryTypeID);
                if (SqlHelper.getInstance.ExcuteScalar("select IssueNo from oddsInfo where IssueNo='" + info.IssueNo + "'") == null)
                    SqlHelper.getInstance.ExcuteNonQuery(sql);
                return SqlHelper.getInstance.ExcuteInsert<LotteryNumsInfo>(info, "LotteryNumsInfo", "LotteryNums,UpdateTime,UpdateUser,Size,Parity");
            }
        }
        public LotteryNumsInfo SetLotteryNumsInfo(int type)
        {
            LotteryNumsInfo l = GetCurrenIssuNum(type);
            if (l == null)
            {
                l = GetLastLotteryNum(type);
                if (l == null)
                    throw new Exception();
                l = CreateModel(l);
                InsertLotteryNums(l);
            }
            return l;
        }
        public bool ManualPaijiang(LotteryType type, string issueNo)
        {
            string sql = "update LotteryNumsInfo set isDistributed=0 where IssueNo='" + issueNo + "'";
            SqlHelper.getInstance.ExcuteNonQuery(sql);
            GoPaiJiang(type);
            WriteLog("手动派奖", "手动派奖,期号:" + issueNo);
            return true;
        }
        private LotteryNumsInfo CreateModel(LotteryNumsInfo info)
        {
            LotteryNumsInfo lni = new LotteryNumsInfo();
            lni.AddTime = System.DateTime.Now;
            lni.AddUser = "autoCollect";
            lni.isDistributed = 0;
            lni.LotteryTypeID = info.LotteryTypeID;
            int lotterType = Convert.ToInt32(info.LotteryTypeID);
            lni.LotteryDate = info.LotteryDate;
            lni.IssueNo = info.IssueNo;
            if (lotterType == (int)LotteryType.SSC)
            {
                //期号    
                string no = (Convert.ToInt32(lni.IssueNo.Substring(8, 3)) + 1).ToString();
                lni.IssueNo = lni.IssueNo.Substring(0, 8);
                if (no.Length == 1)
                    no = "00" + no;
                if (no.Length == 2)
                    no = "0" + no;
                if (Convert.ToInt32(no) == 121)
                {
                    lni.IssueNo = lni.IssueNo.Substring(0, 4) + "-" + lni.IssueNo.Substring(4, 2) + "-" + lni.IssueNo.Substring(6, 2);
                    lni.IssueNo = Convert.ToDateTime(lni.IssueNo).AddDays(1).ToString("yyyyMMdd");
                    no = "001";
                }
                lni.IssueNo = lni.IssueNo + no;
                //开奖时间,10-22点十分钟一次，22-2点5分钟一次
                if ((lni.LotteryDate.Hour < 22 && lni.LotteryDate.Hour > 2))
                {
                    lni.LotteryDate = lni.LotteryDate.AddMinutes(10);
                }
                else if (lni.LotteryDate.ToString("HH:mm:ss") == "01:55:00")
                    lni.LotteryDate = lni.LotteryDate.AddHours(8).AddMinutes(5);
                else
                    lni.LotteryDate = lni.LotteryDate.AddMinutes(5);

            }
            if (lotterType == (int)LotteryType._3D)
            {
                if (lni.LotteryDate.Month == 12 && lni.LotteryDate.Day == 31)
                {
                    lni.LotteryDate = lni.LotteryDate.AddYears(1).Date.AddHours(20).AddMinutes(30);
                    lni.IssueNo = lni.LotteryDate.AddYears(1).Year.ToString() + "001";
                }
                else
                {
                    lni.LotteryDate = lni.LotteryDate.AddDays(1);
                    string no = (Convert.ToInt32(lni.IssueNo.Substring(4, 3)) + 1).ToString();
                    lni.IssueNo = lni.IssueNo.Substring(0, 4);
                    if (no.Length == 2)
                        no = "0" + no;
                    if (no.Length == 1)
                        no = "00" + no;
                    lni.IssueNo = lni.IssueNo + no;
                }
            }
            if (lotterType == (int)LotteryType.SSQ)
            {
                if (lni.LotteryDate.Month == 12 && lni.LotteryDate.Day == 31)
                {
                    if (lni.LotteryDate.DayOfWeek == DayOfWeek.Thursday)
                        lni.LotteryDate = lni.LotteryDate.AddYears(1).Date.AddHours(21).AddMinutes(30).AddDays(3);
                    else
                        lni.LotteryDate = lni.LotteryDate.AddYears(1).Date.AddHours(21).AddMinutes(30).AddDays(2);
                    lni.IssueNo = lni.LotteryDate.AddYears(1).Year.ToString() + "001";
                }
                else
                {
                    if (lni.LotteryDate.DayOfWeek == DayOfWeek.Thursday)
                        lni.LotteryDate = lni.LotteryDate.AddDays(3);
                    else
                        lni.LotteryDate = lni.LotteryDate.AddDays(2);
                    string no = (Convert.ToInt32(lni.IssueNo.Substring(4, 3)) + 1).ToString();
                    lni.IssueNo = lni.IssueNo.Substring(0, 4);
                    if (no.Length == 2)
                        no = "0" + no;
                    if (no.Length == 1)
                        no = "00" + no;
                    lni.IssueNo = lni.IssueNo + no;
                }
            }

            return lni;
        }
        private void GoPaiJiang(LotteryType type)
        {
            List<LotteryNumsInfo> info = getIsNotPJ((int)type);

            foreach (LotteryNumsInfo ln in info)
            {
                try
                {
                    UpdateLotteryFlag(1, ln.LotteryTypeID, ln.IssueNo);
                    //派奖开始
                    List<BetRecord> listOrders = getOrders(ln.IssueNo, (int)type);
                    List<BetRecord> listResult_bet = new List<BetRecord>();
                    List<ProfitLossInfo> listResult_prl = new List<ProfitLossInfo>();
                    foreach (BetRecord order in listOrders)
                    {
                        BetRecord record = JudgeWin(order, ln);
                        listResult_bet.Add(record);
                    }
                    bool returnBool = UpdateOrdersWinInfo(listResult_bet);//更新中奖信息
                    //派奖结束
                    if (returnBool)
                        UpdateLotteryFlag(2, ln.LotteryTypeID, ln.IssueNo);
                }
                catch (Exception e)
                {
                    UpdateLotteryFlag(0, ln.LotteryTypeID, ln.IssueNo);
                }
            }
        }
        private BetRecord JudgeWin(BetRecord record, LotteryNumsInfo ltyNum)
        {

            record.UpdateTime = DateTime.Now;
            record.WinMoney = 0;
            int winCount = 0;
            string winNum = string.Empty;
            string[] betNums;
            string[] arr_winNum;
            string[] arr_odd = null;
            switch ((PlayType)record.PlayTypeID)
            {
                case PlayType._3xZhix://SSC三星直选
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    if (record.PlayTypeRadioID == 1 || record.PlayTypeRadioID == 2)//后三直选
                        winNum = ltyNum.LotteryNums.Substring(2, 3);
                    else//前三直选
                        winNum = ltyNum.LotteryNums.Substring(0, 3);
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        string[] nums = num.Split(',');
                        if (nums.Length != 3 && nums.Length == 1)
                        {
                            if (nums[0] == winNum)
                            {
                                winCount++;
                            }
                            continue;
                        }
                        if (!nums[0].Contains(winNum.First()))
                        {
                            continue;
                        }
                        if (!nums[1].Contains(winNum.Substring(1, 1)))
                        {
                            continue;
                        }
                        if (!nums[2].Contains(winNum.Last()))
                        {
                            continue;
                        }
                        winCount += 1;
                    }
                    break;
                    #endregion
                case PlayType._3xZux://SSC三星组选
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    if (record.PlayTypeRadioID == 5
                        || record.PlayTypeRadioID == 6
                        || record.PlayTypeRadioID == 7)//后三组选
                    {
                        winNum = ltyNum.LotteryNums.Substring(2, 3);
                    }
                    else//前三组选
                    {
                        winNum = ltyNum.LotteryNums.Substring(0, 3);
                    }
                    betNums = record.BetNums.Split('$');
                    if (record.PlayTypeRadioID == 6 || record.PlayTypeRadioID == 9)//买组3
                    {
                        if (JudgeNumsType(winNum) != NumType.Zu3)//开组6或者豹子
                            break;

                    }
                    else if (record.PlayTypeRadioID == 5 || record.PlayTypeRadioID == 8)//买组6
                    {
                        if (JudgeNumsType(winNum) != NumType.Zu6)//开组3或者豹子
                            break;
                    }
                    else//组选混合
                    {
                        foreach (string num in betNums)
                        {
                            if (JudgeNumsType(winNum) != JudgeNumsType(num))//组选混合时形态不一致则未中奖
                                continue;
                            if (num.Contains(winNum.First())
                                && num.Contains(winNum.Substring(1, 1))
                                && num.Contains(winNum.Last()))
                                winCount += 1;
                        }
                        break;
                    }
                    foreach (string num in betNums)
                    {
                        if (num.Contains(winNum.First())
                            && num.Contains(winNum.Substring(1, 1))
                            && num.Contains(winNum.Last()))
                            winCount += 1;
                    }
                    break;
                    #endregion
                case PlayType._2xZhix://SSC二星直选
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    if (record.PlayTypeRadioID == 11 || record.PlayTypeRadioID == 12)//后二直选
                        winNum = ltyNum.LotteryNums.Substring(3, 2);
                    else//前二直选
                        winNum = ltyNum.LotteryNums.Substring(0, 2);
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        string[] nums = num.Split(',');
                        if (nums.Length == 1)
                        {
                            if (nums[0] == winNum)
                            {
                                winCount++;
                            }
                            continue;
                        }
                        if (!nums[0].Contains(winNum.First()))
                        {
                            continue;
                        }
                        if (!nums[1].Contains(winNum.Last()))
                        {
                            continue;
                        }
                        winCount += 1;
                    }
                    break;
                    #endregion
                case PlayType._2xZux://SSC二星组选
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    if (record.PlayTypeRadioID == 15
                        || record.PlayTypeRadioID == 16)//后二组选
                    {
                        winNum = ltyNum.LotteryNums.Substring(3, 2);
                    }
                    else//前二组选
                    {
                        winNum = ltyNum.LotteryNums.Substring(0, 2);
                    }
                    betNums = record.BetNums.Split('$');
                    if (record.PlayTypeRadioID == 15 || record.PlayTypeRadioID == 17)//买组二（不包含组3形态即2个号码相同)
                    {
                        if (winNum.Last() == winNum.First())
                            break;
                    }
                    else//组选二混合
                    {
                        foreach (string num in betNums)
                        {
                            if (JudgeNumsType(num) != JudgeNumsType(winNum))//组选二混合时形态不一直则未中奖
                                continue;
                            if (num.Contains(winNum.First())
                                && num.Contains(winNum.Last()))
                                winCount += 1;
                        }
                        break;
                    }
                    foreach (string num in betNums)
                    {
                        if (num.Contains(winNum.First())
                            && num.Contains(winNum.Last()))
                            winCount += 1;
                    }
                    break;
                    #endregion
                case PlayType._H1Zhix:
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    winNum = ltyNum.LotteryNums.Substring(4, 1);//后一直选
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        if (num.Contains(winNum))
                            winCount += 1;
                    }
                    break;
                    #endregion
                case PlayType._Bddw:
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    winNum = ltyNum.LotteryNums;
                    if (record.PlayTypeRadioID == 20)
                        winNum = winNum.Substring(2, 3);
                    if (record.PlayTypeRadioID == 21)
                        winNum = winNum.Substring(0, 3);
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        for (int i = 0; i < num.Length; i++)
                        {
                            if (winNum.Contains(num.Substring(i, 1)))
                                winCount++;
                        }
                    }
                    break;
                    #endregion
                case PlayType._Ddw:
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    winNum = ltyNum.LotteryNums;
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        if (num.Trim() == string.Empty)
                            continue;
                        string[] nums = num.Split(',');
                        for (int i = 0; i < winNum.Length; i++)
                        {
                            if (nums[i].Contains(winNum.Substring(i, 1)))
                                winCount++;
                        }
                    }
                    break;
                    #endregion
                case PlayType._R3Zhix://RX三星直选
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        bool isMatch = true;
                        string[] _nums = num.Split(',');
                        for (int i = 0; i < 5; i++)
                        {
                            if (_nums[i].Trim() == string.Empty)
                                continue;
                            else
                            {
                                if (!_nums[i].Contains(ltyNum.LotteryNums.Substring(i, 1)))
                                {
                                    isMatch = false;
                                    break;
                                }
                            }
                        }
                        if (isMatch)
                            winCount++;
                    }
                    break;
                    #endregion
                case PlayType._R3Zux://RX三星组选
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    string str = record.PlayTypeDirection.Substring(record.PlayTypeDirection.IndexOf("(") + 1,
                        record.PlayTypeDirection.IndexOf(")") - record.PlayTypeDirection.IndexOf("(") - 2);
                    string[] checkboxs = str.Split(',');
                    foreach (string cb in checkboxs)
                    {
                        switch (cb.ToLower())
                        {
                            case "万":
                                winNum = winNum + ltyNum.LotteryNums.Substring(0, 1);
                                break;
                            case "千":
                                winNum = winNum + ltyNum.LotteryNums.Substring(1, 1);
                                break;
                            case "百":
                                winNum = winNum + ltyNum.LotteryNums.Substring(2, 1);
                                break;
                            case "十":
                                winNum = winNum + ltyNum.LotteryNums.Substring(3, 1);
                                break;
                            case "个":
                                winNum = winNum + ltyNum.LotteryNums.Substring(4, 1);
                                break;
                        }
                    }
                    betNums = record.BetNums.Split('$');
                    if (record.PlayTypeRadioID == 49)//买组3
                    {
                        if (JudgeNumsType(winNum) != NumType.Zu3)//开组6或者豹子
                            break;

                    }
                    else if (record.PlayTypeRadioID == 50)//买组6
                    {
                        if (JudgeNumsType(winNum) != NumType.Zu6)//开组3或者豹子
                            break;
                    }
                    else//组选混合
                    {
                        foreach (string num in betNums)
                        {
                            if (JudgeNumsType(winNum) != JudgeNumsType(num))//组选混合时形态不一致则未中奖
                                continue;
                            if (num.Contains(winNum.First())
                                && num.Contains(winNum.Substring(1, 1))
                                && num.Contains(winNum.Last()))
                                winCount += 1;
                        }
                        break;
                    }
                    foreach (string num in betNums)
                    {
                        if (num.Contains(winNum.First())
                            && num.Contains(winNum.Substring(1, 1))
                            && num.Contains(winNum.Last()))
                            winCount += 1;
                    }
                    break;
                    #endregion
                case PlayType._R2Zhix://RX二星直选
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        bool isMatch = true;
                        string[] _nums = num.Split(',');
                        for (int i = 0; i < 5; i++)
                        {
                            if (_nums[i].Trim() == string.Empty)
                                continue;
                            else
                            {
                                if (!_nums[i].Contains(ltyNum.LotteryNums.Substring(i, 1)))
                                {
                                    isMatch = false;
                                    break;
                                }
                            }
                        }
                        if (isMatch)
                            winCount++;
                    }
                    break;
                    #endregion
                case PlayType._R2Zux://RX二星组选
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    string str2 = record.PlayTypeDirection.Substring(record.PlayTypeDirection.IndexOf("(") + 1,
                        record.PlayTypeDirection.IndexOf(")") - record.PlayTypeDirection.IndexOf("(") - 2);
                    string[] checkboxs2 = str2.Split(',');
                    foreach (string cb in checkboxs2)
                    {
                        switch (cb.ToLower())
                        {
                            case "万":
                                winNum = winNum + ltyNum.LotteryNums.Substring(0, 1);
                                break;
                            case "千":
                                winNum = winNum + ltyNum.LotteryNums.Substring(1, 1);
                                break;
                            case "百":
                                winNum = winNum + ltyNum.LotteryNums.Substring(2, 1);
                                break;
                            case "十":
                                winNum = winNum + ltyNum.LotteryNums.Substring(3, 1);
                                break;
                            case "个":
                                winNum = winNum + ltyNum.LotteryNums.Substring(4, 1);
                                break;
                        }
                    }
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        if (JudgeNumsType(winNum) != JudgeNumsType(num))//组选混合时形态不一致则未中奖
                            continue;
                        if (num.Contains(winNum.First())
                            && num.Contains(winNum.Substring(1, 1))
                            && num.Contains(winNum.Last()))
                            winCount += 1;
                    }
                    break;
                    #endregion
                case PlayType._Rbdw://RX任不定位
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    winNum = ltyNum.LotteryNums;
                    if (record.PlayTypeRadioID == 56)
                        winNum = winNum.Substring(2, 3);
                    if (record.PlayTypeRadioID == 57)
                        winNum = winNum.Substring(0, 3);
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        for (int i = 0; i < num.Length; i++)
                        {
                            if (winNum.Contains(num.Substring(i, 1)))
                                winCount++;
                        }
                    }
                    break;
                    #endregion
                case PlayType._Rydw://RX任意定位
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    winNum = ltyNum.LotteryNums;
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        string[] nums = num.Split(',');
                        for (int i = 0; i < winNum.Length; i++)
                        {
                            if (nums[i].Contains(winNum.Substring(i, 1)))
                                winCount++;
                        }
                    }
                    break;
                    #endregion

                case PlayType._3DZhix:
                    #region
                    if (ltyNum.LotteryNums.Length != 3)
                        break;
                    winNum = ltyNum.LotteryNums;
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        string[] nums = num.Split(',');
                        if (nums.Length != 3 && nums.Length == 1)
                        {
                            if (nums[0] == winNum)
                            {
                                winCount++;
                            }
                            continue;
                        }
                        if (!nums[0].Contains(winNum.First()))
                        {
                            continue;
                        }
                        if (!nums[1].Contains(winNum.Substring(1, 1)))
                        {
                            continue;
                        }
                        if (!nums[2].Contains(winNum.Last()))
                        {
                            continue;
                        }
                        winCount += 1;
                    }
                    break;
                    #endregion
                case PlayType._3DZux:
                    #region
                    if (ltyNum.LotteryNums.Length != 3)
                        break;
                    winNum = ltyNum.LotteryNums;
                    betNums = record.BetNums.Split('$');
                    if (record.PlayTypeRadioID == 27)//买组3
                    {
                        if (JudgeNumsType(winNum) != NumType.Zu3)//开组6或者豹子
                            break;

                    }
                    else if (record.PlayTypeRadioID == 26)//买组6
                    {
                        if (JudgeNumsType(winNum) != NumType.Zu6)//开组3或者豹子
                            break;
                    }
                    else//组选混合
                    {
                        foreach (string num in betNums)
                        {
                            if (JudgeNumsType(winNum) != JudgeNumsType(num))//组选混合时形态不一致则未中奖
                                continue;
                            if (num.Contains(winNum.First())
                                && num.Contains(winNum.Substring(1, 1))
                                && num.Contains(winNum.Last()))
                                winCount += 1;
                        }
                        break;
                    }
                    foreach (string num in betNums)
                    {
                        if (num.Contains(winNum.First())
                            && num.Contains(winNum.Substring(1, 1))
                            && num.Contains(winNum.Last()))
                            winCount += 1;
                    }
                    break;
                    #endregion
                case PlayType._3D2xZhix:
                    #region
                    if (ltyNum.LotteryNums.Length != 3)
                        break;
                    winNum = ltyNum.LotteryNums.Substring(1, 2);
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        string[] nums = num.Split(',');
                        if (nums.Length == 1)
                        {
                            if (nums[0] == winNum)
                            {
                                winCount++;
                            }
                            continue;
                        }
                        if (!nums[0].Contains(winNum.First()))
                        {
                            continue;
                        }
                        if (!nums[1].Contains(winNum.Last()))
                        {
                            continue;
                        }
                        winCount += 1;
                    }
                    break;
                    #endregion
                case PlayType._3D2xZux:
                    #region
                    if (ltyNum.LotteryNums.Length != 3)
                        break;
                    winNum = ltyNum.LotteryNums.Substring(1, 2);
                    betNums = record.BetNums.Split('$');
                    if (record.PlayTypeRadioID == 31)//买组二（不包含组3形态即2个号码相同)
                    {
                        if (winNum.Last() == winNum.First())
                            break;
                    }
                    else//组选二混合
                    {
                        foreach (string num in betNums)
                        {
                            if (JudgeNumsType(num) != JudgeNumsType(winNum))//组选二混合时形态不一直则未中奖
                                continue;
                            if (num.Contains(winNum.First())
                                && num.Contains(winNum.Last()))
                                winCount += 1;
                        }
                    }
                    foreach (string num in betNums)
                    {
                        if (num.Contains(winNum.First())
                            && num.Contains(winNum.Last()))
                            winCount += 1;
                    }
                    break;
                    #endregion
                case PlayType._3DH1Zhix:
                    #region
                    if (ltyNum.LotteryNums.Length != 3)
                        break;
                    winNum = ltyNum.LotteryNums.Substring(2, 1);//后一直选
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        if (num.Contains(winNum))
                            winCount += 1;
                    }
                    break;
                    #endregion
                case PlayType._3DBddw:
                    #region
                    if (ltyNum.LotteryNums.Length != 3)
                        break;
                    winNum = ltyNum.LotteryNums;
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        for (int i = 0; i < num.Length; i++)
                        {
                            if (winNum.Contains(num.Substring(i, 1)))
                                winCount++;
                        }
                    }
                    break;
                    #endregion
                case PlayType._3DDdw:
                    #region
                    if (ltyNum.LotteryNums.Length != 3)
                        break;
                    winNum = ltyNum.LotteryNums;
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        string[] nums = num.Split(',');
                        for (int i = 0; i < winNum.Length; i++)
                        {
                            if (nums[i].Contains(winNum.Substring(i, 1)))
                                winCount++;
                        }
                    }
                    break;
                    #endregion
                case PlayType._SSQBlue:
                    #region
                    if (ltyNum.LotteryNums.Split(',').Length != 7)
                        break;
                    arr_winNum = ltyNum.LotteryNums.Split(',');
                    winNum = arr_winNum[6];
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        string[] nums = num.Split(',');
                        if (nums.Contains(winNum))
                            winCount++;
                    }
                    break;
                    #endregion
                case PlayType._SSQRed:
                    #region
                    if (ltyNum.LotteryNums.Split(',').Length != 7)
                        break;
                    winNum = ltyNum.LotteryNums.Substring(0, ltyNum.LotteryNums.Length - 3);
                    arr_winNum = winNum.Split(',');
                    betNums = record.BetNums.Split('$');
                    foreach (string num in betNums)
                    {
                        string[] nums = num.Split(',');
                        foreach (string _num in arr_winNum)
                        {
                            if (nums.Contains(_num))
                                winCount++;
                        }
                    }
                    break;
                    #endregion
                case PlayType.NSSCBdw:
                    #region
                    if (ltyNum.LotteryNums.Length != 5)
                        break;
                    winNum = ltyNum.LotteryNums;
                    if (record.PlayTypeRadioID == 38)
                        winNum = winNum.Substring(4, 1);
                    if (record.PlayTypeRadioID == 39)
                        winNum = winNum.Substring(3, 2);
                    if (record.PlayTypeRadioID == 40)
                        winNum = winNum.Substring(2, 3);
                    if (!winNum.Contains(record.BetNums))
                    {
                        winCount++;
                        record.WinMoney = record.BetMoney * 2;
                    }
                    break;
                    #endregion
                case PlayType.N3DBdw:
                    #region
                    if (ltyNum.LotteryNums.Length != 3)
                        break;
                    winNum = ltyNum.LotteryNums;
                    if (record.PlayTypeRadioID == 42)
                        winNum = winNum.Substring(2, 1);
                    if (record.PlayTypeRadioID == 43)
                        winNum = winNum.Substring(1, 2);
                    if (!winNum.Contains(record.BetNums))
                    {
                        winCount++;
                        record.WinMoney = record.BetMoney * 2;
                    }
                    break;
                    #endregion
                case PlayType.NSSQBlue:
                    #region
                    if (ltyNum.LotteryNums.Split(',').Length != 7)
                        break;
                    arr_winNum = ltyNum.LotteryNums.Split(',');
                    winNum = arr_winNum[6];
                    if (!winNum.Contains(record.BetNums))
                    {
                        winCount++;
                        record.WinMoney = record.BetMoney * 2;
                    }
                    break;
                    #endregion
                case PlayType.NSSQRed:
                    #region
                    if (ltyNum.LotteryNums.Split(',').Length != 7)
                        break;
                    winNum = ltyNum.LotteryNums.Substring(0, ltyNum.LotteryNums.Length - 3);
                    if (!winNum.Contains(record.BetNums))
                    {
                        winCount++;
                        record.WinMoney = record.BetMoney * 2;
                    }
                    break;
                    #endregion
            }
            record.IsWin = winCount == 0 ? 0 : 1;
            record.WinCount = winCount;
            if ((PlayType)record.PlayTypeID != PlayType.N3DBdw
                && (PlayType)record.PlayTypeID != PlayType.NSSCBdw
                && (PlayType)record.PlayTypeID != PlayType.NSSQBlue
                && (PlayType)record.PlayTypeID != PlayType.NSSQRed)
            {
                arr_odd = record.OddBonus.Split('/');
                record.WinMoney = Math.Round(Convert.ToDouble(arr_odd[0]) * record.BetMultiple * record.WinCount, 2);
            }
            return record;
        }
        NumType JudgeNumsType(string num)
        {
            if (num.Length == 3)
            {
                string num_1 = num.Substring(0, 1);
                string num_2 = num.Substring(1, 1);
                string num_3 = num.Substring(2, 1);
                if (num_1 == num_2 && num_2 == num_3)
                    return NumType.BaoZ;
                else if (num_1 != num_2 && num_1 != num_3 && num_2 != num_3)
                {
                    return NumType.Zu6;
                }
                else
                    return NumType.Zu3;
            }
            else
            {
                string num_1 = num.Substring(0, 1);
                string num_2 = num.Substring(1, 1);
                if (num_1 == num_2)
                    return NumType.Zu3;
                else
                    return NumType.Zu6;
            }
        }
        //=================开奖用==================End
        public List<LotteryNumsInfo> getIsNotPJ(int type)
        {
            string sql = "select * from LotteryNumsInfo where LotteryTypeID=" + type +
     " and (isDistributed=0 or isDistributed=1) and LotteryNums!='' and LotteryNums is not null";
            return SqlHelper.getInstance.ExcuteForList<LotteryNumsInfo>(sql);
        }
        public List<LotteryNumsInfo> updatePjStatus(int status, int type)
        {
            string sql = "update LotteryNumsInfo set isDistributed=" + status +
                " where  LotteryTypeID=" + type +
                " and isDistributed=0 and LotteryNums!='' and LotteryNums is not null";
            return SqlHelper.getInstance.ExcuteForList<LotteryNumsInfo>(sql);
        }
        public List<BetRecord> getOrders(string IssueNo, int type)
        {
            string sql = @"select * from BetRecord where IssueNo='" + IssueNo +
             "' and ResultStatus=0 and LotteryTypeID in(select LotteryTypeID from LotteryTypeInfo where LotteryID=" + type + ")";
            return SqlHelper.getInstance.ExcuteForList<BetRecord>(sql);
        }
        public int UpdateLotteryFlag(int Flag, Int64 LotteryId, string issueNo)
        {
            string sql = string.Format("update LotteryNumsInfo set isDistributed={0} where LotteryTypeID={1} and IssueNo='{2}'", Flag, LotteryId, issueNo);
            return SqlHelper.getInstance.ExcuteNonQuery(sql);
        }
        public int UpdateOrdersWinInfo(BetRecord record)
        {
            string sql = string.Format(@"update BetRecord  set ResultStatus=1,WinCount={0},
                            WinMoney={1},IsWin={2},UpdateTime='{3}' where RecordID={4}",
                            record.WinCount, record.WinMoney, record.IsWin,
                            record.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss"), record.RecordID);
            return SqlHelper.getInstance.ExcuteNonQuery(sql);
        }
        public User GetUserInfo(string userid)
        {
            string sql = String.Format("select * from UserInfo where userid='{0}'", userid);
            return SqlHelper.getInstance.ExcuteForList<User>(sql).FirstOrDefault();
        }
        public bool UpdateOrdersWinInfo(List<BetRecord> betrecord_list)
        {
            List<ProfitLossInfo> pfl_list = new List<ProfitLossInfo>();
            List<Capital> capital_list = new List<Capital>();
            //admin账户========
            User userAdmin = GetAdmin();
            Capital cpAdmin = GetCapitalInfo(userAdmin.UserId);
            //=================
            foreach (BetRecord record in betrecord_list)
            {
                Capital cp = new Capital();
                if (capital_list.Exists(p => p.UserId == record.UserID))
                {
                    cp = capital_list.Find(p => p.UserId == record.UserID);
                    capital_list.Remove(cp);
                }
                else
                    cp = GetCapitalInfo(record.UserID);
                if (cp == null)
                    continue;
                if (record.Direction == 0)
                {
                    cp.GameScores = Math.Round(cp.GameScores + record.WinMoney - record.BetMoney + Math.Round(record.BonusPct / 100 * record.BetMoney, 2), 2);
                    cp.EnableScores = Math.Round(cp.EnableScores + record.WinMoney, 2);
                    cp.DisableScores = Math.Round(cp.DisableScores - (record.BetMoney - Math.Round(record.BonusPct / 100 * record.BetMoney, 2)), 2);
                }
                else
                {
                    User user = GetUserInfo(record.UserID);
                    if (record.IsWin == 1)
                    {
                        double disabledS = record.BetMoney * (Convert.ToDouble(record.OddBonus) - 1);
                        cp.GameScores = Math.Round(cp.GameScores + record.BetMoney + Math.Round(record.BetMoney * user.Bonus / 100, 2), 2);
                        cp.EnableScores = Math.Round(cp.EnableScores + record.BetMoney * (Convert.ToDouble(record.OddBonus) - 1) + record.BetMoney, 2);
                        cp.DisableScores = Math.Round(cp.DisableScores - record.BetMoney * (Convert.ToDouble(record.OddBonus) - 1)
                            + Math.Round(record.BetMoney * user.Bonus / 100, 2), 2);
                    }
                    else
                    {
                        cp.GameScores = Math.Round(cp.GameScores - record.BetMoney + Math.Round(record.BetMoney * user.Bonus / 100, 2), 2);
                        cp.EnableScores = cp.EnableScores + record.BetMoney * (Convert.ToDouble(record.OddBonus) - 1) - record.BetMoney;
                        cp.DisableScores = Math.Round(cp.DisableScores - record.BetMoney * (Convert.ToDouble(record.OddBonus) - 1)
                            + Math.Round(record.BetMoney * user.Bonus / 100, 2), 2);
                    }
                }
                capital_list.Add(cp);
                //admin
                if (record.Direction == 0 || (record.Direction == 1 && record.IsWin == 1))
                    cpAdmin.GameScores = Math.Round(cpAdmin.GameScores - record.WinMoney, 2);
                else
                    cpAdmin.GameScores = Math.Round(cpAdmin.GameScores + record.BetMoney * (Convert.ToDouble(record.OddBonus) - 1) - record.BetMoney, 2);
                pfl_list.Add(new ProfitLossInfo()
                {
                    RecordID = record.RecordID,
                    ProfitLossMoney = record.Direction == 0 ? Math.Round(record.WinMoney - record.BetMoney + Math.Round(record.BonusPct / 100 * record.BetMoney, 2), 2) :
                    (record.IsWin == 1 ? Math.Round(record.WinMoney - record.BetMoney + Math.Round(record.BonusPct / 100 * record.BetMoney, 2), 2) : (-record.BetMoney * (Convert.ToDouble(record.OddBonus) - 1))),
                    ProfitLossTime = DateTime.Now,
                    UserID = record.UserID,
                    Memo = record.PlayTypeDirection,
                    ProfitLossType = "盈亏",
                    CurrentEnableScores = cp.EnableScores
                });
                //admin
                pfl_list.Add(new ProfitLossInfo()
                {
                    RecordID = record.RecordID,
                    ProfitLossMoney = record.Direction == 0 ? Math.Round(-record.WinMoney, 2) :
                    (record.IsWin == 1 ? Math.Round(-record.WinMoney, 2) : (record.BetMoney * (Convert.ToDouble(record.OddBonus) - 1) - record.BetMoney)),
                    ProfitLossTime = DateTime.Now,
                    UserID = userAdmin.UserId,
                    Memo = record.UserID + "中奖,下注金额:" + record.BetMoney.ToString() + ",中奖金额:" + record.WinMoney.ToString() + ",玩法:" + record.PlayTypeDirection,
                    ProfitLossType = "盈亏",
                    CurrentEnableScores = cpAdmin.GameScores
                });
            }
            //admin
            capital_list.Add(cpAdmin);
            List<SQLTranCationParaMeters> tran_list = new List<SQLTranCationParaMeters>();
            SQLTranCationParaMeters para = new SQLTranCationParaMeters();
            para.SqlText = @"update BetRecord  set ResultStatus=1,WinCount=@WinCount,
                            WinMoney=@WinMoney,IsWin=@IsWin,UpdateTime=@UpdateTime where RecordID=@RecordID";
            para.ParameterName = new string[] { "WinCount", "WinMoney", "IsWin", "UpdateTime", "RecordID" };
            para.Data = ConvertHelper.ToListDictionary<BetRecord>(betrecord_list);
            para.type = typeof(BetRecord);
            tran_list.Add(para);

            para = new SQLTranCationParaMeters();
            para.SqlText = @"Insert into ProfitLoss values(@UserID,@ProfitLossTime,@Memo,@ProfitLossType,
                             @CurrentEnableScores,@RecordID,@ProfitLossMoney)";
            para.ParameterName = new string[] { "UserID", "ProfitLossTime","Memo","ProfitLossType", 
                                                "CurrentEnableScores", "RecordID", "ProfitLossMoney"};
            para.Data = ConvertHelper.ToListDictionary<ProfitLossInfo>(pfl_list);
            para.type = typeof(ProfitLossInfo);
            tran_list.Add(para);

            para = new SQLTranCationParaMeters();
            para.SqlText = @"update CapitalInfo set GameScores=@GameScores,EnableScores=@EnableScores,DisableScores=@DisableScores
                            where UserID=@UserID";
            para.ParameterName = new string[] { "GameScores", "EnableScores", "DisableScores", "UserId" };
            para.Data = ConvertHelper.ToListDictionary<Capital>(capital_list);
            para.type = typeof(Capital);
            tran_list.Add(para);
            return SqlHelper.getInstance.ExcuteInsertTrancation(tran_list);
        }
        //=================开奖用==================End
        public Capital GetCapitalInfo(string userid)
        {
            string sql = String.Format("select * from CapitalInfo where userid='{0}'", userid);
            List<Capital> list = SqlHelper.getInstance.ExcuteForList<Capital>(sql);
            return list.FirstOrDefault();
        }
        #endregion
        #region hlj
        public List<LotteryInfo> GetLotteryInfo(string lotteryName, string isEnable, string Orientation)
        {
            string sql = "select * from LotteryTypeInfo where LotteryName like '%{0}%' and IsEnable like '%{1}%' and Orientation like '%{2}%'";
            sql = string.Format(sql, lotteryName, isEnable, Orientation);
            return SqlHelper.getInstance.ExcuteForList<LotteryInfo>(sql);
        }
        public List<PlayTypeInfo> GetPlayTypeInfoByLotteryId(Int64 lotteryId)
        {
            string sql = @"select a.*,b.LotteryTypeID,b.LotteryName,b.Orientation 
                         from PlayTypeInfo a left join  LotteryTypeInfo b on a.LotteryTypeID=b.LotteryTypeID 
                         where a.LotteryTypeID={0}";
            sql = string.Format(sql, lotteryId);
            return SqlHelper.getInstance.ExcuteForList<PlayTypeInfo>(sql);
        }
        public List<PlayTypeInfo> GetPlayTypeInfo(string lotteryName, string isEnable, string Orientation, string playTypeName)
        {
            string sql = @"select a.*,b.LotteryTypeID,b.LotteryName,b.Orientation 
                         from PlayTypeInfo a left join  LotteryTypeInfo b on a.LotteryTypeID=b.LotteryTypeID 
                         where b.LotteryName like '%{0}%' and a.IsEnable like '%{1}%' and b.Orientation like '%{2}%' 
                                and a.PlayTypeName like '%{3}%'";
            sql = string.Format(sql, lotteryName, isEnable, Orientation, playTypeName);
            return SqlHelper.getInstance.ExcuteForList<PlayTypeInfo>(sql);
        }
        public List<PlayTypeRadioInfo> GetPlayRadioInfoByPlayTyPeId(Int64 playTypeId)
        {
            string sql = @"select c.LotteryName,c.Orientation,c.LotteryTypeID,b.PlayTypeName,b.PlayTypeID,a.* 
                          from PlayTypeRadio a left join PlayTypeInfo b on a.PlayTypeId=b.PlayTypeId
                          left join LotteryTypeInfo c on b.LotteryTypeID=c.LotteryTypeID
                          where a.PlayTypeID={0}";
            sql = string.Format(sql, playTypeId);
            return SqlHelper.getInstance.ExcuteForList<PlayTypeRadioInfo>(sql);
        }
        public List<PlayTypeRadioInfo> GetPlayRadioInfo(string lotteryName, string isEnable, string Orientation,
                                                        string playTypeName, string playRadioName)
        {
            string sql = @"select c.LotteryName,c.Orientation,c.LotteryTypeID,b.PlayTypeName,b.PlayTypeID,a.* 
                          from PlayTypeRadio a left join PlayTypeInfo b on a.PlayTypeId=b.PlayTypeId
                          left join LotteryTypeInfo c on b.LotteryTypeID=c.LotteryTypeID
                          where c.LotteryName like '%{0}%' and c.IsEnable like '%{1}%' and c.Orientation like '%{2}%' 
                          and b.PlayTypeName like '%{3}%' and a.PlayTypeRadioName like '%{4}%'";
            sql = string.Format(sql, lotteryName, isEnable, Orientation, playTypeName, playRadioName);
            return SqlHelper.getInstance.ExcuteForList<PlayTypeRadioInfo>(sql);
        }
        public bool UpdateLotteryIsEnable(LotteryInfo isEnable)
        {
            string sql = string.Format("update LotteryTypeInfo set IsEnable={0} where LotteryTypeID={1}", isEnable.IsEnable, isEnable.LotteryTypeID);
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("修改彩种启用状态", "修改彩种启用状态" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<LotteryInfo>(isEnable));
            return execResult;
        }
        public bool UpdateLotteryIsOpen(LotteryInfo isOpen)
        {
            string sql = string.Format("update LotteryTypeInfo set IsOpen={0} where LotteryTypeID={1}", isOpen.IsOpen, isOpen.LotteryTypeID);
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("修改彩种开放状态", "修改彩种开放状态" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<LotteryInfo>(isOpen));
            return execResult;
        }
        public bool UpdateLotteryName(LotteryInfo lottery)
        {
            string sql = string.Format("update LotteryTypeInfo set LotteryName='{0}' where LotteryTypeID={1}", lottery.LotteryName, lottery.LotteryTypeID);
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("修改彩种名称", "修改彩种名称" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<LotteryInfo>(lottery));
            return execResult;
        }
        public bool UpdatePlayTypeIsEnable(PlayTypeInfo isEnable)
        {
            string sql = string.Format("update PlayTypeInfo set IsEnable={0} where PlayTypeID={1}", isEnable.IsEnable, isEnable.PlayTypeID);
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("修改玩法状态", "修改玩法状态" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<PlayTypeInfo>(isEnable));
            return execResult;
        }
        public bool UpdatePlayTypeName(PlayTypeInfo lottery)
        {
            string sql = string.Format("update PlayTypeInfo set PlayTypeName='{0}' where PlayTypeID={1}", lottery.PlayTypeName, lottery.PlayTypeID);
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("修改玩法名称", "修改玩法名称" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<PlayTypeInfo>(lottery));
            return execResult;
        }
        public bool UpdatePlayRadioIsEnable(PlayTypeRadioInfo isEnable)
        {
            string sql = string.Format("update PlayTypeRadio set IsEnable={0} where PlayTypeRadioID={1}", isEnable.IsEnable, isEnable.PlayTypeRadioID);
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("修改玩法单选状态", "修改玩法单选状态" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<PlayTypeRadioInfo>(isEnable));
            return execResult;
        }
        public bool UpdatePlayRadioName(PlayTypeRadioInfo lottery)
        {
            string sql = string.Format("update PlayTypeRadio set PlayTypeRadioName='{0}' where PlayTypeRadioID={1}", lottery.PlayTypeRadioName, lottery.PlayTypeRadioID);
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("修改玩法单选名称", "修改玩法单选名称" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<PlayTypeRadioInfo>(lottery));
            return execResult;
        }
        public List<LotteryInfo> GetAllLotteryInfo()
        {
            string sql = @"select case when Orientation=0 then LotteryName+'[正向]' else LotteryName+'[逆向]' end as LotteryName,
                        Orientation,LotteryTypeID,IsEnable from LotteryTypeInfo";
            return SqlHelper.getInstance.ExcuteForList<LotteryInfo>(sql);
        }
        public List<PlayTypeInfo> GetAllPlayTypeInfo()
        {
            string sql = @"select * from PlayTypeInfo";
            return SqlHelper.getInstance.ExcuteForList<PlayTypeInfo>(sql);
        }
        public List<PlayTypeRadioInfo> GetPlayTypeRadioForBonus(string lotteryId, string playTypeName, Int64 orientation, string playTypeRadioName)
        {
            string sql = @"select c.*,a.PlayTypeID,a.PlayTypeName,b.LotteryTypeID,b.LotteryName,b.Orientation 
                           from PlayTypeRadio c left join  PlayTypeInfo a on c.PlayTypeId=a.PlayTypeId 
                           left join LotteryTypeInfo b on a.LotteryTypeID=b.LotteryTypeID 
                           where Orientation={1}  and a.PlayTypeName like '%{0}%' and c.PlayTypeRadioName like'%{2}%'";
            if (lotteryId != "")
            {
                sql = sql + " and  a.LotteryTypeID ={3} ";
                sql = string.Format(sql, playTypeName, orientation, playTypeRadioName, lotteryId);
            }
            else
                sql = string.Format(sql, playTypeName, orientation, playTypeRadioName);
            return SqlHelper.getInstance.ExcuteForList<PlayTypeRadioInfo>(sql);
        }
        public List<Odds> GetDefaultOdds(string lotteryId, string playTypeName, string playRadioName)
        {
            string sql = @"select a.*,b.PlayTypeName,c.PlayTypeRadioName,d.LotteryTypeID,d.LotteryName 
                           from DefaultOddsInfo a left join PlayTypeInfo b on a.PlayTypeID=b.PlayTypeID 
                           left join PlayTypeRadio c on a.PlayTypeRadioID=c.PlayTypeRadioID  
                           left join LotteryTypeInfo d on b.LotteryTypeID=d.LotteryTypeID 
                           where b.PlayTypeName like '%{0}%' and c.PlayTypeRadioName like '%{1}%' ";
            if (lotteryId != "")
            {
                sql = sql + " and d.LotteryTypeID ={2}";
                sql = string.Format(sql, playTypeName, playRadioName, lotteryId);
            }
            else
                sql = string.Format(sql, playTypeName, playRadioName);
            return SqlHelper.getInstance.ExcuteForList<Odds>(sql);
        }
        public List<Odds> GetCurrentOdds(string lotteryId, string playTypeName, string playRadioName)
        {
            string sql = @"select a.*,b.PlayTypeName,c.PlayTypeRadioName,d.LotteryTypeID,d.LotteryName 
                           from OddsInfo a left join PlayTypeInfo b on a.PlayTypeID=b.PlayTypeID 
                           left join PlayTypeRadio c on a.PlayTypeRadioID=c.PlayTypeRadioID  
                           left join LotteryTypeInfo d on b.LotteryTypeID=d.LotteryTypeID 
                           where b.PlayTypeName like '%{0}%' and c.PlayTypeRadioName like '%{1}%' and a.IssueNo in ({2}) ";
            string IssuNo = GetCurrenIssuNo(lotteryId);
            if (lotteryId != "")
            {
                sql = sql + " and d.LotteryTypeID ={3}";
                sql = string.Format(sql, playTypeName, playRadioName, IssuNo, lotteryId);
            }
            else
                sql = string.Format(sql, playTypeName, playRadioName, IssuNo);
            List<Odds> list = SqlHelper.getInstance.ExcuteForList<Odds>(sql);
            return list;
        }
        public bool UpdatePlayTypeRadioBonus(PlayTypeRadioInfo info)
        {
            string sql = @"update PlayTypeRadio set
                           BaseScale={0},MinScale={1} 
                           where PlayTypeRadioID={2}";
            sql = string.Format(sql, info.BaseScale, info.MinScale, info.PlayTypeRadioID);
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("修改玩法赔率", "修改玩法赔率" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<PlayTypeRadioInfo>(info));
            return execResult;
        }
        public bool UpdateDefaultOdds(Odds info)
        {
            string sql = @"update DefaultOddsInfo set NumOdds={0},AllCount={1} 
                            where PlayTypeID={2} and PlayTypeRadioID={3} and Num='{4}'";
            sql = string.Format(sql, info.NumOdds, info.AllCount, info.PlayTypeID, info.PlayTypeRadioID, info.Num);
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("修改默认赔率", "修改默认赔率" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<Odds>(info));
            return execResult;
        }
        public bool UpdateCurrentOdds(Odds info)
        {
            string sql = @"update OddsInfo set NumOdds={0},RemainderCount={1} 
                            where PlayTypeID={2} and PlayTypeRadioID={3} and Num='{4}' and IssueNo='{5}'";
            sql = string.Format(sql, info.NumOdds, info.AllCount, info.PlayTypeID, info.PlayTypeRadioID, info.Num, info.IssueNo);
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("修改当前期赔率", "修改[" + info.IssueNo + "]期赔率" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<Odds>(info));
            return execResult;
        }
        public List<BetRecord> GetBetRecord(Int64 playTypeId, Int64 recordId, Int64 lotteryId, string isPj, string userid, string winorlose, string dateStart, string dateEnd)
        {
            string sql = @"select a.*,b.LotteryName,c.PlayTypeName 
                            from BetRecord a left join LotteryTypeInfo b on  a.LotteryTypeID=b.LotteryTypeID
                            left join PlayTypeInfo c on a.PlayTypeId=c.PlayTypeId where 1=1";
            if (lotteryId != 0)
                sql += (" and a.LotteryTypeID=" + lotteryId);
            if (recordId != 0)
                sql += (" and a.RecordID=" + recordId);
            if (playTypeId != 0)
                sql += (" and  a.PlayTypeID=" + playTypeId);
            if (isPj != "")
                sql += (" and a.ResultStatus=" + isPj);
            if (userid.Trim() != "")
                sql += (" and a.UserID='" + userid + "'");
            if (winorlose != "")
                sql += (" and a.IsWin=" + winorlose);
            sql += " and BetTime between '" + dateStart + "' and '" + dateEnd + "'";
            sql += " order by RecordID desc";
            return SqlHelper.getInstance.ExcuteForList<BetRecord>(sql);

        }

        public User GetAdmin()
        {
            string sqlGetAdmin = "select * from UserInfo where ParentUID is null";
            User userAdmin = SqlHelper.getInstance.ExcuteForList<User>(sqlGetAdmin).FirstOrDefault();
            return userAdmin;
        }
        public List<ProfitReport> GetProfitReport(string userid, DateTime start, DateTime end)
        {
            string sql = @"select *,PctMoney+ProfitLoss-BetMoney as AllProfitLoss,
                                         MoneyIn+MoneyOut as Liquidity
                                         from (select UserID,
                                         sum(case when t3.ProfitLossType ='充值' then t3.ProfitLossMoney else 0 end) as MoneyIn,
                                         sum(case when t3.ProfitLossType ='提现' then t3.ProfitLossMoney else 0 end) as MoneyOut,
                                         0-sum(case when t3.ProfitLossType ='投注' then t3.ProfitLossMoney else 0 end) as BetMoney,
                                         sum(case when t3.ProfitLossType ='返点' then t3.ProfitLossMoney else 0 end) as PctMoney,
                                         sum(case when t3.ProfitLossType ='提现返点' then t3.ProfitLossMoney else 0 end) as PctMoneyOut,
                                         sum(case when t3.ProfitLossType ='盈亏' then t3.ProfitLossMoney else 0 end) as ProfitLoss 
                                         from  ProfitLoss t3   
                                         where t3.ProfitLossTime between '{0}' and '{1}' and  UserID{3}'{2}'  
                                         group by UserID ) a";
            if (userid != "")
                sql = string.Format(sql, start.ToString("yyyy-MM-dd HH:mm:ss"), end.ToString("yyyy-MM-dd HH:mm:ss"), userid, "=");
            else
                sql = string.Format(sql, start.ToString("yyyy-MM-dd HH:mm:ss"), end.ToString("yyyy-MM-dd HH:mm:ss"), GetAdmin().UserId, "!=");
            List<ProfitReport> list = SqlHelper.getInstance.ExcuteForList<ProfitReport>(sql);
            return list;
        }
        public List<ProfitDetail> GetProfitDetail(string userid, string type, DateTime start, DateTime end)
        {
            string sql = @"select RecordID,ProfitLossTime,Memo,ProfitLossType,ProfitLossMoney,CurrentEnableScores,UserID
                           from  ProfitLoss where ProfitLossTime between '{0}' and '{1}' and UserID!='{2}'";
            sql = string.Format(sql, start.ToString("yyyy-MM-dd HH:mm:ss"), end.ToString("yyyy-MM-dd HH:mm:ss"), GetAdmin().UserId);
            if (userid != "")
                sql += (" and UserID='" + userid + "'");
            if (type != "")
                sql += (" and ProfitLossType='" + type + "'");
            sql += "order by RecordID desc,ProfitLossTime desc";
            List<ProfitDetail> list = SqlHelper.getInstance.ExcuteForList<ProfitDetail>(sql);
            return list;
        }
        public List<ProfitReport> GetAdminProfitReport(DateTime start, DateTime end)
        {
            string sql = string.Format(@"select *,PctMoney+ProfitLoss+BetMoney as AllProfitLoss,
                                         MoneyIn+MoneyOut as Liquidity
                                         from (select UserID,
                                         sum(case when t3.ProfitLossType ='充值' then t3.ProfitLossMoney else 0 end) as MoneyIn,
                                         sum(case when t3.ProfitLossType ='提现' then t3.ProfitLossMoney else 0 end) as MoneyOut,
                                         sum(case when t3.ProfitLossType ='投注' then t3.ProfitLossMoney else 0 end) as BetMoney,
                                         sum(case when t3.ProfitLossType ='返点' then t3.ProfitLossMoney else 0 end) as PctMoney,
                                         sum(case when t3.ProfitLossType ='提现返点' then t3.ProfitLossMoney else 0 end) as PctMoneyOut,
                                         sum(case when t3.ProfitLossType ='盈亏' then t3.ProfitLossMoney else 0 end) as ProfitLoss 
                                         from  ProfitLoss t3   
                                         where t3.ProfitLossTime between '{0}' and '{1}' and  UserID='{2}'  
                                         group by UserID) a",
                                         start.ToString("yyyy-MM-dd HH:mm:ss"), end.ToString("yyyy-MM-dd HH:mm:ss"), GetAdmin().UserId);
            List<ProfitReport> list = SqlHelper.getInstance.ExcuteForList<ProfitReport>(sql);
            return list;
        }
        public List<ProfitDetail> GetAdminProfitDetail(string type, DateTime start, DateTime end)
        {
            string sql = @"select RecordID,ProfitLossTime,Memo,ProfitLossType,ProfitLossMoney,CurrentEnableScores
                           from  ProfitLoss where ProfitLossTime between '{0}' and '{1}' ";
            sql = string.Format(sql, start.ToString("yyyy-MM-dd HH:mm:ss"), end.ToString("yyyy-MM-dd HH:mm:ss"));
            string userid = GetAdmin().UserId;
            if (userid != "")
                sql += (" and UserID='" + userid + "'");
            if (type != "")
                sql += (" and ProfitLossType='" + type + "'");
            sql += "order by RecordID desc,ProfitLossTime desc";
            List<ProfitDetail> list = SqlHelper.getInstance.ExcuteForList<ProfitDetail>(sql);
            return list;
        }
        public List<CarrierBankInfo> GetCarrierBank()
        {
            return SqlHelper.getInstance.ExcuteForList<CarrierBankInfo>("select * from CarrierBankInfo");
        }
        public bool ChangeBankEnable(CarrierBankInfo bankInfo)
        {
            string sql = "update CarrierBankInfo set IsEnable=" + bankInfo.IsEnable + " where ID=" + bankInfo.ID;
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("修改平台银行状态", "修改平台银行状态" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<CarrierBankInfo>(bankInfo));
            return execResult;
        }
        public bool UpdateBank(CarrierBankInfo bankInfo)
        {
            string sql = "select * from CarrierBankInfo where ID=" + bankInfo.ID;
            bool execResult = true;
            if (SqlHelper.getInstance.ExcuteExist(sql))
            {
                //修改
                sql = "update  CarrierBankInfo set AccountName='{0}',AccountNum='{1}',BankType='{2}',BankName='{3}',IsEnable={4} where ID={5}";
                sql = string.Format(sql, bankInfo.AccountName, bankInfo.AccountNum, bankInfo.BankType, bankInfo.BankName, bankInfo.IsEnable, bankInfo.ID);
                execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
                WriteLog("修改平台银行", "修改平台银行" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<CarrierBankInfo>(bankInfo));
            }
            else
            {
                //新增
                sql = "insert into CarrierBankInfo(AccountName,AccountNum,BankType,BankName,IsEnable) values('{0}','{1}','{2}','{3}',{4})";
                sql = string.Format(sql, bankInfo.AccountName, bankInfo.AccountNum, bankInfo.BankType, bankInfo.BankName, bankInfo.IsEnable);
                execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
                WriteLog("新增平台银行", "新增平台银行" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<CarrierBankInfo>(bankInfo));
            }
            return execResult;
        }
        public List<News> GetNews(int type, int isEnable)
        {
            string sql = "select * from News where 1=1 ";
            if (type != -1)
                sql += (" and NewsType=" + type);
            if (isEnable != -1)
                sql += (" and isEnable=" + isEnable);
            return SqlHelper.getInstance.ExcuteForList<News>(sql);
        }
        public bool UpdateNews(News news)
        {
            string sql = "select * from News where NewsID=" + news.NewsID;
            bool execResult = true;
            if (SqlHelper.getInstance.ExcuteExist(sql))
            {
                //修改
                sql = "update  News set NewsType={0},NewsContent='{1}',UrlAddress='{2}',IsEnable={3} where NewsID={4}";
                sql = string.Format(sql, news.NewsType, news.NewsContent, news.UrlAddress, news.IsEnable, news.NewsID);
                execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
                WriteLog("修改公告", "修改公告" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<News>(news));
            }
            else
            {
                //新增
                sql = "insert into News(NewsType,NewsContent,UrlAddress,IsEnable,AddTime) values({0},'{1}','{2}',{3},'{4}')";
                sql = string.Format(sql, news.NewsType, news.NewsContent, news.UrlAddress, news.IsEnable, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
                WriteLog("新增公告", "新增公告" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<News>(news));
            }
            return execResult;
        }
        public bool ChangeNewEnable(News news)
        {
            string sql = "update  News set IsEnable={0} where NewsID={1}";
            sql = string.Format(sql, news.IsEnable, news.NewsID);
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("修改公告状态", "修改公告状态" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<News>(news));
            return execResult;
        }
        public string ValidateLogin(string userId, string pwd)
        {
            string returnValue = string.Empty;
            string sql = "select * from UserInfo where UserID='{0}' and UserPwd='{1}' and RoleID=1";
            sql = string.Format(sql, userId, pwd);
            bool result = SqlHelper.getInstance.ExcuteExist(sql);
            if (result)
            {
                sql = "select LastLoginTime from UserInfo where UserID='" + userId + "'";
                object lastLoginTm = SqlHelper.getInstance.ExcuteScalar(sql);
                if (lastLoginTm != null)
                    returnValue = Convert.ToDateTime(lastLoginTm.ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                sql = string.Format("update UserInfo set LastLoginTime='{0}' where userid='{1}' ",
                   DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), userId);
                SqlHelper.getInstance.ExcuteNonQuery(sql);
                HttpContext.Current.Session["UserID"] = userId;
                WriteLog("登录", userId + "于" + DateTime.Now.ToString() + "登录系统成功");
            }
            else
            {
                WriteLog("登录", userId + "于" + DateTime.Now.ToString() + "登录系统失败");
            }
            return returnValue;
        }
        public int WriteLog(string logTitle, string logContent)
        {
            Log log = new Log();
            log.BfOrBehind = 1;
            log.LogIp = "";
            log.LogTime = DateTime.Now;
            if (HttpContext.Current.Session["UserID"] != null)
                log.UserID = HttpContext.Current.Session["UserID"].ToString();
            else
                log.UserID = string.Empty;
            log.LogTitle = logTitle;
            log.LogContent = logContent;
            return SqlHelper.getInstance.ExcuteInsert<Log>(log, "Log");
        }
        public string GetLogContent<T>(T t)
        {
            StringBuilder sb = new StringBuilder();
            System.Reflection.PropertyInfo[] propertys = t.GetType().GetProperties();
            foreach (System.Reflection.PropertyInfo p in propertys)
            {
                sb.Append("[" + p.Name + "=" + p.GetValue(t, null) + "],");
            }
            if (sb.Length > 0)
                return "{" + sb.ToString().Substring(0, sb.Length - 1) + "}";
            else
                return string.Empty;
        }
        public string GetLogContent(Dictionary<int, string> values)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < values.Count; i++)
            {
                sb.Append(values[i] + ",");
            }
            if (values.Count > 0)
                return "{" + sb.ToString().Substring(0, sb.Length - 1) + "}";
            else
                return string.Empty;
        }
        public bool ChangeAdminPwd(string userId, string pwd)
        {
            string sql = "update UserInfo set UserPwd='{0}' where UserID='{1}'";
            sql = string.Format(sql, pwd, userId);
            bool execResult = (SqlHelper.getInstance.ExcuteNonQuery(sql) > 0) ? true : false;
            WriteLog("修改密码", "修改" + userId + "登录密码为:" + pwd + (execResult == true ? "成功" : "失败"));
            return execResult;
        }
        #endregion
        public List<Log> GetBgLogData(string userName, string titile, DateTime dtFrom, DateTime dtTo)
        {
            string sql = string.Empty;
            if (string.IsNullOrEmpty(userName))
            {
                sql = String.Format("select UserID,LogTitle,LogContent,LogTime,LogIp from Log where LogTime>='{0}' and LogTime<='{1}' and BfOrBehind=1 ", dtFrom, dtTo);
            }
            else
            {
                sql = String.Format("select UserID,LogTitle,LogContent,LogTime,LogIp from Log where userid='{0}' and LogTime>='{1}' and LogTime<='{2}' and BfOrBehind=1 ", userName, dtFrom, dtTo);
            }
            if (titile != string.Empty)
            {
                sql += (" and LogTitle='" + titile + "'");
            }
            sql += " order by LogTime desc";
            return SqlHelper.getInstance.ExcuteForList<Log>(sql);
        }
        public List<Log> GetFgLogData(string userName, DateTime dtFrom, DateTime dtTo)
        {
            string sql = string.Empty;
            if (string.IsNullOrEmpty(userName))
            {
                sql = String.Format("select UserID,LogContent,LogTime,LogIp from Log where LogTime>='{0}' and LogTime<='{1}' and BfOrBehind=0 order by LogTime desc", dtFrom, dtTo);
            }
            else
            {
                sql = String.Format("select UserID,LogContent,LogTime,LogIp from Log where userid='{0}' and LogTime>='{1}' and LogTime<='{2}' and BfOrBehind=0 order by LogTime desc", userName, dtFrom, dtTo);
            }
            return SqlHelper.getInstance.ExcuteForList<Log>(sql);
        }
        public bool AddLottery(LotteryInfo info)
        {
            if (SqlHelper.getInstance.ExcuteInsert<LotteryInfo>(info, "LotteryTypeInfo", "LotteryID,LotteryTypeID") > 0)
                return true;
            else
                return false;
        }
        public bool DeleteNews(News news)
        {
            string sql = "delete from News where NewsID=" + news.NewsID;
            bool execResult = SqlHelper.getInstance.ExcuteNonQuery(sql) > 0 ? true : false;
            WriteLog("删除公告", "删除公告" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<News>(news));
            return execResult;
        }
        public bool DeletePlatformBank(CarrierBankInfo info)
        {
            string sql = "delete from CarrierBankInfo where ID=" + info.ID;
            bool execResult = SqlHelper.getInstance.ExcuteNonQuery(sql) > 0 ? true : false;
            WriteLog("删除平台银行", "删除平台银行" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<CarrierBankInfo>(info));
            return execResult;
        }
        public bool DeleteBetRecord(BetRecord record)
        {
            Capital cp = GetCapitalInfo(record.UserID);
            User user = GetUserInfo(record.UserID);
            if (record.Direction == 1)//逆向
            {
                cp.EnableScores = Math.Round(cp.EnableScores + Math.Round(record.BetMoney * (Convert.ToDouble(record.OddBonus) - 1), 2)
                    - Math.Round(record.BetMoney * user.Bonus / 100, 2), 2);
                cp.DisableScores = Math.Round(cp.DisableScores - Math.Round(record.BetMoney * (Convert.ToDouble(record.OddBonus) - 1), 2)
                    + Math.Round(record.BetMoney * user.Bonus / 100, 2), 2);
            }
            else
            {
                cp.EnableScores = Math.Round(cp.EnableScores + record.BetMoney - Math.Round(record.BonusPct / 100 * record.BetMoney, 2), 2);
                cp.DisableScores = Math.Round(cp.DisableScores - record.BetMoney + Math.Round(record.BonusPct / 100 * record.BetMoney, 2), 2);
            }
            cp.GameScores = Math.Round(cp.GameScores, 2);
            ProfitLossInfo info = SqlHelper.getInstance.ExcuteForList<ProfitLossInfo>(
            @"select * from ProfitLossInf where RecordId=" + record.RecordID + " and UserID='" + record.UserID + "' and ProfitLossType='投注'").FirstOrDefault();
            if (info != null)
                return false;
            string[] sqls = new string[3];
            sqls[0] = "delete from BetRecord where RecordID=" + record.RecordID;
            sqls[1] = "delete from ProfitLossInfo where RecordID=" + record.RecordID;
            sqls[2] = string.Format("update CapitalInfo set EnableScores={0},DisableScores={1},GameScores={2} where UserId='{3}'",
                       cp.EnableScores, cp.DisableScores, cp.GameScores, cp.UserId);
            bool execResult = SqlHelper.getInstance.ExcuteTrancationForSQL(sqls);
            WriteLog("撤销投注记录", "撤销投注记录" + (execResult == true ? "成功" : "失败") + ",Value" + GetLogContent<BetRecord>(record));
            return execResult;
        }
        /// <summary>
        /// 获取当前彩票类型ID，同一种类型的只有一个ID
        /// </summary>
        /// <returns></returns>
        public int GetCurrentLotteryID()
        {
            string sql = "SELECT count(DISTINCT lotteryid) FROM LotteryTypeInfo";
            object o = SqlHelper.getInstance.ExcuteScalar(sql);
            int i = 1;
            int.TryParse(o.ToString(), out i);
            if (i == -1)
            {
                i = 1;
            }
            return i;
        }
    }
}
